﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace WorldEvolution
{
    /// <summary>
    /// 世界组成的基本元素 金木水火土
    /// </summary>
    [StructLayout(LayoutKind.Sequential,Pack =1)]
    public struct ElementData
    {
        public static int StructSize = Marshal.SizeOf(typeof(ElementData));

        public byte Golden;
        public byte Wood;
        public byte Water;
        public byte Fire;
        public byte Soil;

        public void FillData(byte[] buffer,int start)
        {
            Golden = buffer[start]; start++;
            Wood = buffer[start]; start++;
            Water = buffer[start]; start++;
            Fire = buffer[start]; start++;
            Soil = buffer[start];
            //             Golden = BitConverter.ToUInt16(buffer, start);
            //             start += Marshal.SizeOf(Golden);
            //             Wood = BitConverter.ToUInt16(buffer, start );
            //             start += Marshal.SizeOf(Wood);
            //             Water = BitConverter.ToUInt16(buffer, start);
            //             start += Marshal.SizeOf(Water);
            //             Fire = BitConverter.ToUInt16(buffer, start);
            //             start += Marshal.SizeOf(Fire);
            //             Soil = BitConverter.ToUInt16(buffer, start);
        }

        public void ToBuffer(byte[] buffer, int start)
        {
            Buffer.BlockCopy(BitConverter.GetBytes(Golden), 0, buffer, start, Marshal.SizeOf(Golden));
            start += Marshal.SizeOf(Golden);
            Buffer.BlockCopy(BitConverter.GetBytes(Wood), 0, buffer, start, Marshal.SizeOf(Wood));
            start += Marshal.SizeOf(Wood);
            Buffer.BlockCopy(BitConverter.GetBytes(Water), 0, buffer, start, Marshal.SizeOf(Water));
            start += Marshal.SizeOf(Water);
            Buffer.BlockCopy(BitConverter.GetBytes(Fire), 0, buffer, start, Marshal.SizeOf(Fire));
            start += Marshal.SizeOf(Fire);
            Buffer.BlockCopy(BitConverter.GetBytes(Soil), 0, buffer, start, Marshal.SizeOf(Soil));
        }
    }
}
